<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN">
<head><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    <title>6.52. Sysvinit-2.86</title>
    <link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
    <link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css" media="print" />
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head>
  <body id="lfs" class="6.2">
    <div class="navheader">
      <div class="headertitles">
        <h4>Linux From Scratch - 版本 6.2</h4>
        <h3>第六章 安装系统基础软件</h3>
      </div>
      <ul class="headerlinks">
        <li class="prev">
          <a accesskey="p" href="sysklogd.html" title="Sysklogd-1.4.1">后退</a>
          <p>Sysklogd-1.4.1</p>
        </li>
        <li class="next">
          <a accesskey="n" href="tar.html" title="Tar-1.15.1">前进</a>
          <p>Tar-1.15.1</p>
        </li>
        <li class="up"><a accesskey="u" href="chapter06.html" title="第六章 安装系统基础软件">上一级</a></li>
        <li class="home"><a accesskey="h" href="../index.html" title="Linux From Scratch - 版本 6.2">首页</a></li>
      </ul>
    </div>
    <div class="wrap">
      <div class="titlepage">
        <h1 class="sect1">6.52. Sysvinit-2.86</h1>
      </div>
      <div class="package">
        <p>Sysvinit 软件包包含一些控制系统启动、运行、关闭的程序。</p>
        <div class="segmentedlist">
          <div class="seglistitem">
            <div class="seg">
              <strong><span class="segtitle">预计编译时间：</span></strong> <span class="seg">少于 0.1 SBU</span>
            </div>
            <div class="seg">
              <strong><span class="segtitle">所需磁盘空间：</span></strong> <span class="seg">1 MB</span>
            </div>
          </div>
        </div>
      </div>
      <div class="installation">
        <div class="titlepage">
          <h2 class="sect2">6.52.1. 安装 Sysvinit</h2>
        </div>
        <p>当运行级别被改变(比如，正在关闭系统)，<span><strong class="command">init</strong></span> 向那些由 <span><strong class="command">init</strong></span> 自身开启的，并且将不会在新的运行级别里运行的线程发送终端信号。当 <span><strong class="command">init</strong></span> 做上面这些事情时，会输出像"<span class="quote">Sending processes the TERM signal</span>"这样的信息，这看起来就像它正在向那些系统正在运行的程序发送上面这些信息一样。要避免错误地理解这个信息，可以修改源码以便可以代替为读起来像"<span class="quote">Sending processes started by init the TERM signal</span>"的信息，可以用下面命令：</p>
        <pre class="userinput"><kbd class="command">sed -i 's@Sending processes@&amp; started by init@g' \
    src/init.c</kbd></pre>
        <p>编译软件包：</p>
        <pre class="userinput"><kbd class="command">make -C src</kbd></pre>
        <p>这个软件包没有附带测试程序。</p>
        <p>安装软件包：</p>
        <pre class="userinput"><kbd class="command">make -C src install</kbd></pre>
      </div>
      <div class="configuration">
        <div class="titlepage">
          <a id="conf-sysvinit" name="conf-sysvinit"></a>
          <h2 class="sect2">6.52.2. 配置 Sysvinit</h2>
        </div>
        <p>运行下面命令，创建一个新的 <tt class="filename">/etc/inittab</tt> 文件：</p>
        <pre class="userinput"><kbd class="command">cat &gt; /etc/inittab &lt;&lt; "EOF"
<tt class="literal"># Begin /etc/inittab

id:3:initdefault:

si::sysinit:/etc/rc.d/init.d/rc sysinit

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty tty1 9600
2:2345:respawn:/sbin/agetty tty2 9600
3:2345:respawn:/sbin/agetty tty3 9600
4:2345:respawn:/sbin/agetty tty4 9600
5:2345:respawn:/sbin/agetty tty5 9600
6:2345:respawn:/sbin/agetty tty6 9600

# End /etc/inittab</tt>
EOF</kbd></pre>
      </div>
      <div class="content">
        <div class="titlepage">
          <a id="contents-sysvinit" name="contents-sysvinit"></a>
          <h2 class="sect2">6.52.3. Sysvinit 的内容</h2>
        </div>
        <div class="segmentedlist">
          <div class="seglistitem">
            <div class="seg">
              <strong><span class="segtitle">安装的程序：</span></strong> <span class="seg">bootlogd, halt,
              init, killall5, last, lastb(→last), mesg, mountpoint,
              pidof(→killall5), poweroff(→halt), reboot(→halt), runlevel, shutdown, sulogin, telinit(→init),
              utmpdump, wall</span>
            </div>
          </div>
        </div>
        <div class="variablelist">
          <h3><a id="id3694920" name="id3694920"></a>简要描述</h3>
          <table border="0">
            <col align="left" valign="top" />
            <tbody>
              <tr>
                <td><a id="bootlogd" name="bootlogd"></a><span class="term"><span><strong class="command">bootlogd</strong></span></span></td>
                <td><p>把启动信息记录到一个日志文件</p></td>
              </tr>
              <tr>
                <td><a id="halt" name="halt"></a><span class="term"><span><strong class="command">halt</strong></span></span></td>
                <td><p>正常情况下等效于 <span><strong class="command">shutdown</strong></span> 加上 <em class="parameter"><tt>-h</tt></em> 参数(当前系统运行级别是 0 时除外)。它将告诉内核去中止系统，并在系统正在关闭的过程中将日志记录到 <tt class="filename">/var/log/wtmp</tt> 文件里。</p></td>
              </tr>
              <tr>
                <td><a id="init" name="init"></a><span class="term"><span><strong class="command">init</strong></span></span></td>
                <td><p>当内核已经初始化硬件，接管引导程序，开启指令线程时，init 会被第一个启动。</p></td>
              </tr>
              <tr>
                <td><a id="killall5" name="killall5"></a><span class="term"><span><strong class="command">killall5</strong></span></span></td>
                <td><p>发送一个信号到所有进程，但那些在它自己设定级别的进程将不会被这个运行的脚本所中断。</p></td>
              </tr>
              <tr>
                <td><a id="last" name="last"></a><span class="term"><span><strong class="command">last</strong></span></span></td>
                <td><p>给出哪一个用户最后一次登录(或退出登录)，它搜索 <tt class="filename">/var/log/wtmp</tt> 文件，出给出系统引导、关闭、运行级别改变等信息。</p></td>
              </tr>
              <tr>
                <td><a id="lastb" name="lastb"></a><span class="term"><span><strong class="command">lastb</strong></span></span></td>
                <td><p>给出登失败的尝试，并写入日志 <tt class="filename">/var/log/btmp</tt></p></td>
              </tr>
              <tr>
                <td><a id="mesg" name="mesg"></a><span class="term"><span><strong class="command">mesg</strong></span></span></td>
                <td><p>控制是否允许其他用户也有向系统所有用户发送信息的权限</p></td>
              </tr>
              <tr>
                <td><a id="mountpoint" name="mountpoint"></a><span class="term"><span><strong class="command">mountpoint</strong></span></span></td>
                <td><p>检查给定的目录是否是一个挂载点</p></td>
              </tr>
              <tr>
                <td><a id="pidof" name="pidof"></a><span class="term"><span><strong class="command">pidof</strong></span></span></td>
                <td><p>报告给定程序的PID号</p></td>
              </tr>
              <tr>
                <td><a id="poweroff" name="poweroff"></a><span class="term"><span><strong class="command">poweroff</strong></span></span></td>
                <td><p>告诉内核中止系统并且关闭系统(参见 <span><strong class="command">halt</strong></span>)</p></td>
              </tr>
              <tr>
                <td><a id="reboot" name="reboot"></a><span class="term"><span><strong class="command">reboot</strong></span></span></td>
                <td><p>告诉内核重启系统(参见 <span><strong class="command">halt</strong></span>)</p></td>
              </tr>
              <tr>
                <td><a id="runlevel" name="runlevel"></a><span class="term"><span><strong class="command">runlevel</strong></span></span></td>
                <td><p>告前一个和当前的系统运行级别，并且将最后一些运行级别写入 <tt class="filename">/var/run/utmp</tt></p></td>
              </tr>
              <tr>
                <td><a id="shutdown" name="shutdown"></a><span class="term"><span><strong class="command">shutdown</strong></span></span></td>
                <td><p>使系统安全关闭，向所有线程发送关闭信号并且通知所有已经登录的系统用户系统即将关闭。</p></td>
              </tr>
              <tr>
                <td><a id="sulogin" name="sulogin"></a><span class="term"><span><strong class="command">sulogin</strong></span></span></td>
                <td><p>允许 <span class="emphasis"><em>root</em></span> 登录，它通常情况下是在系统在单用户模式下运行时，由 <span><strong class="command">init</strong></span> 所派生。</p></td>
              </tr>
              <tr>
                <td><a id="telinit" name="telinit"></a><span class="term"><span><strong class="command">telinit</strong></span></span></td>
                <td><p>告诉 <span><strong class="command">init</strong></span> 将切换到那一个运行级</p></td>
              </tr>
              <tr>
                <td><a id="utmpdump" name="utmpdump"></a><span class="term"><span><strong class="command">utmpdump</strong></span></span></td>
                <td><p>以一个多用户友好的方式列出已经给出的登录文件的目录</p></td>
              </tr>
              <tr>
                <td><a id="wall" name="wall"></a><span class="term"><span><strong class="command">wall</strong></span></span></td>
                <td><p>向所有已经登录的用户写入一个信息</p></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="sysklogd.html" title="Sysklogd-1.4.1">后退</a>
          <p>Sysklogd-1.4.1</p>
        </li>
        <li class="next">
          <a accesskey="n" href="tar.html" title="Tar-1.15.1">前进</a>
          <p>Tar-1.15.1</p>
        </li>
        <li class="up"><a accesskey="u" href="chapter06.html" title="第六章 安装系统基础软件">上一级</a></li>
        <li class="home"><a accesskey="h" href="../index.html" title="Linux From Scratch - 版本 6.2">首页</a>.
        </li>
      </ul>
    </div>
</body></html>
